<?php

$dep_id = isset($_GET['dep_id']) ? $_GET['dep_id'] : null;

if ($dep_id){
    require_once('./dbfunc.php');
    require_once('./dbparam.php');
    
    header('Content-Type: json');
    
    $conn = conn_mysql();

    $sql = "
            select co_id, co_name
                from huangcz_course, huangcz_major
                where co_major = ma_id
                and ma_dep = ?;
    ";

    $stmt = $conn->prepare($sql);
    $stmt->bind_param('i', $dep_id);

    // 结果参数
    $co_id = 0;
    $co_name = '';

    $stmt->bind_result($co_id, $co_name);
    $stmt->execute();
    $stmt->store_result();

    $response = [];
    while($stmt->fetch()){
        $response[] = [
            'co_id' => $co_id,
            'co_name' => $co_name
        ];
    }

    $stmt->free_result();

    exit(json_encode($response, JSON_UNESCAPED_UNICODE));
}else{
    exit(json_encode([]));
}


